#include <length.h>
#include <OSProc.h>
#include <BasicMatic.h>
#include <MC.h>

//#define NOW
//#define ROOT 

//extern volatile _mch kmemory;
#define _KMalloc(size) Kmalloc(&kmemory,size)
#define _KFree(ptr)    Kfree(&kmemory,ptr)

char* GetStreamPath(_ptlong mstream)
{//Stack.
  
  
}

_ptlong GetStream(char* path, _ptlong root = 0)
{
  if(root != 0 && path[0] == '/')
    return 0;
  if(root == 0 && path[0] != '/')
    return 0;
  _ptlong len;
  char* copy = _Memcpy(path,_KMalloc( len = (strlength(path) + 1)),len);
  
  if(path[0] == '/')
    {
      _ptlong ret =  _GetStream(++copy,ROOT);
      _KFree(copy);
      return ret;
    }
  else
    {
      _ptlong ret = _GetStream(copy,root);
      _KFree(copy);
      return ret;
    }
}

static _ptlong _GetStream(char* path,_ptlong root)
{
  _ptlong next;
  return ((next = FindNextOf(path,'/',0)) == 0
	  ?(_ptlong)FindStream(path,root)
	  :_GetStream(path + next + 1,FindStream((path[next] = '\0',path),root)));//notice the 'next' location 
}

